﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Threading;
using System.Windows.Forms;
using bll;

namespace TimeIt.beispiele
{
    public partial class controlling : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            bll.clsUserCollection _UserCol = new bll.clsUserCollection();
            bll.clsUser _clsIdUser = new bll.clsUser();
            Int32 sessionId = bll.clsUser.Session;
            if (sessionId == 0) { Response.Redirect("login.aspx"); }
            _clsIdUser = _UserCol.GetUserNameBySessionId();
            UserName.Text = _clsIdUser.Title + " " + _clsIdUser.Name;
        }

        protected void Calendar1_SelectionChanged(object sender, EventArgs e)
        {
            txtDate.Text = "";
            foreach (DateTime day in Calendar1.SelectedDates)
            {
                txtDate.Text += day.Date.ToShortDateString();
            }
        }

        protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        /// <summary>
        /// wird bei Klick des Einfügen-Knopfs aufgerufen
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void btninsert_Click(object sender, System.EventArgs e)
        {
            bll.clsTimeSheet newTime = new bll.clsTimeSheet();
            bll.clsTimeSheetCollection myTimeCol = new bll.clsTimeSheetCollection();

            newTime.UserID = bll.clsUser.Session;
            newTime.ProjectID = Convert.ToInt32(txtProject.Text);
            newTime.Date = Convert.ToDateTime(txtDate.Text);
            newTime.Hours = Convert.ToInt32(txtHours.Text);
            newTime.Description = txtDescription.Text;
            newTime.Chargeable = checkChargeable.Checked;

            if (myTimeCol.InsertTimeSheet(newTime) == 1)
                checkMsg.Text = "Einfügen von Arbeitszeit (Stunden: " + newTime.Hours + " Datum: " + newTime.Date + ") für Projekt " + newTime.ProjectID + " erfolgreich!"
                    +"   Bitte kein Pagereload, da sonst Zeit nochmal eingetragen wird!";
            else
                checkMsg.Text = "Einfügen von Arbeitszeit (Stunden: " + newTime.Hours + " Datum: " + newTime.Date + ") für Projekt " + newTime.ProjectID + " FEHLGESCHLAGEN!!!";
        }
    }
}